
    BetaEst = function(x.delta.d, z, d, f.z.x.est, weights){
        
        ipw.objective = function(beta){
            obj = (t(x.delta.d * weights) %*% ( d * (2*z - 1) / f.z.x.est - 
                                         tanh(x.delta.d %*% beta) ))
            return(sum(obj^2))
        }
            
        startpars = rep(0,dim(x.delta.d)[2])
        opt = Optimize(ipw.objective, startpars)
        
        return(opt)
        
    }